package homework;

import java.lang.reflect.Array;
import java.util.Arrays;

public class HomeWork9_26 {
    public static void main(String[] args) {
//        int[] arr= {3,0,1};
//        System.out.println(missingNumber(arr));
        int[] arr = {1,2,3,4,5,6,7};
        rotate(arr,3);
        System.out.println(Arrays.toString(arr));
    }
    //leetcode17.04.消失的数字
    public static int missingNumber(int[] nums) {
        int n = nums.length;
        int sum1 = 0,sum2 = 0;
        for(int i = 0 ; i <= n ;i++){
            sum1 += i;
        }
        for(int j = 0;j < n;j++){
            sum2 += nums[j];
        }
        int ret = sum1 - sum2;
        return ret;
    }
    //leetcode189.轮转数组
    public static void rotate(int[] nums, int k) {
        k %= nums.length;
        reverse(nums, 0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);
    }

    public static void reverse(int[] nums, int start, int end) {
        while (start < end) {
            int temp = nums[start];
            nums[start] = nums[end];
            nums[end] = temp;
            start += 1;
            end -= 1;
        }
    }
}


